import request from '@api/request';
import { HttpUrl } from '@api/httpUrl';
import { useUserStore } from '@/store/modules/user';

// 创建出库信息
export function createOutBound(
    createType: 'import' | 'system',
    customerId: string,
    orderData: any[],
    creator: string = useUserStore().username,
    creatorId: string = useUserStore().id
) {
    return request.post(HttpUrl.createOutBound, { createType, customerId, orderData, creator, creatorId });
}

// 撤销出库信息
export function cancelOutBound(outboundId: string, creator: string = useUserStore().username, creatorId: string = useUserStore().id) {
    return request.put(HttpUrl.cancelOutBound, { outboundId, creator, creatorId });
}

// 获取出库列表
export function getOutBoundList(customerId: string, outbound: boolean) {
    return request.get<AjaxResponse['outBoundList']>(HttpUrl.getOutBoundList, { params: { customerId, outbound } });
}

// 获取时间段出库列表
export function getTodayOutBoundList(dataRange: Date[]) {
    return request.get<AjaxResponse['outBoundList']>(HttpUrl.getTodayOutBoundList, { params: { dataRange } });
}

// 打印出库单
export function printOutBound(
    outboundId: string,
    printTime: Date,
    outboundPerson: string = useUserStore().username,
    outboundPersonId: string = useUserStore().id
) {
    return request.put(HttpUrl.printOutBound, { outboundId, printTime, outboundPerson, outboundPersonId });
}

// 客户产品出货分析
export function getCustomerProductOutbound(customerId: string, productId: string, type: 'year' | 'month' | 'day', startDate: Date, endDate: Date) {
    return request.get<{ month: string; quantity: number }[]>(HttpUrl.getCustomerProductOutbound, {
        params: { customerId, productId, type, startDate, endDate },
    });
}
